import { createSlice } from '@reduxjs/toolkit'




export const commonDataSlice = createSlice({
    name: 'commonData',
    initialState: {
        userInfo: {},
        schoolInfo: {},
        currentIdentity: {}, //当前身份信息
        selectUserList: [],
        env: 'weapp',
        lg_ic: '',
        token: '',
        pageType: '', //页面路径
        baseAddr: '', //基础平台地址
        leaveAddr: '',//请假系统地址
        oaAddr: '',//oa地址
        searchHistory: [],  //搜索历史记录
        avatarAddr:''
    },
    reducers: {
        setUserInfo: (state, action) => {
            state.userInfo = Object.assign({}, state.userInfo, action.payload)
        },
        setSchoolInfo: (state, action) => {
            state.schoolInfo = Object.assign({}, state.schoolInfo, action.payload)
        },
        setSelectUser: (state, action) => {
            state.selectUserList = action.payload
        },
        clearSelectList: (state, action) => {
            state.selectUserList = []
        },
        setEnv: (state, action) => {  //当前环境值 app h5 weapp
            state.env = action.payload
        },
        setToken: (state, action) => {  //每次进入存入全局token
            state.token = action.payload
        },
        setIdentity: (state, action) => {
            state.lg_ic = action.payload
        },
        setCurrentIdentity: (state, action) => {
            state.currentIdentity = action.payload
        },
        setPageType: (state, action) => {
            state.pageType = action.payload
        },
        setOaAddr: (state, action) => {  //oa地址
            state.oaAddr = action.payload
        },
        setBaseAddr: (state, action) => { //基础平台地址
            state.oaAddr = action.payload
        },
        setLeaveAddr: (state, action) => {  //请假地址
            state.leaveAddr = action.payload
        },
        setAvatarAddr: (state, action) => {  //请假地址
            state.avatarAddr = action.payload
        },
        setSearchHistory: (state, action) => {  //请假地址
            state.searchHistory = action.payload
        },
    },
})

export const {
    setUserInfo,
    setSelectUser,
    setSchoolInfo,
    clearSelectList, //清除选择的抄送人
    setEnv,
    setToken,
    setCurrentIdentity,
    setIdentity,
    setPageType,
    setOaAddr,
    setBaseAddr,
    setLeaveAddr,
    setSearchHistory,
    setAvatarAddr
} = commonDataSlice.actions

export default commonDataSlice.reducer